package com.zxx.pattern.chainPattern.chain4_broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

/**
 * @author zxx on 2021/2/23
 */
public class ThirdReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        int limit = intent.getIntExtra("limit", -1001);

        Log.e("Tag-->", "Third: " + limit);
        if (limit == 10) {
            String msg = intent.getStringExtra("msg");

            //获取上一个Receiver增加的消息
            Bundle b = getResultExtras(true);
            String str = b.getString("new2");

            Toast.makeText(context, msg + " -3- " + str, Toast.LENGTH_SHORT).show();

            abortBroadcast();
        } else {
            Bundle bundle = new Bundle();
            bundle.putString("new", "Message from Third");
            setResultExtras(bundle);
        }
    }
}
